﻿Imports System.Drawing.Printing
Imports System.Management
Imports System.DirectoryServices
Public Class ConfigPrinter
    Private Sub ConfigPrinter_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            LoadAllPrinter()
        Catch ex As Exception

        End Try
    End Sub
#Region "Function"
    Private Sub LoadAllPrinter()
        Try
            Dim pkInstalledPrinters As String
            ' Find all printers installed
            For Each pkInstalledPrinters In _
                PrinterSettings.InstalledPrinters
                cboInstalledPrinters.Items.Add(pkInstalledPrinters)
            Next pkInstalledPrinters

            ' Set the combo to the first printer in the list
            cboInstalledPrinters.SelectedIndex = 0
        Catch ex As Exception

        End Try
    End Sub
#End Region

    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        Try
            'write file
            Dim PrinterName As String = cboInstalledPrinters.Text
            Dim CurrentDir As String = IO.Path.GetDirectoryName(Application.ExecutablePath)
            Dim PathConfigFile As String = CurrentDir + "\PrinterDefault.txt"
            Dim encrypt As New Common
            System.IO.File.WriteAllText(PathConfigFile, PrinterName)
            Me.Close()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        Try
            Me.Close()
        Catch ex As Exception

        End Try
    End Sub
End Class